
package com.zll.framework.util;


import org.apache.poi.hssf.usermodel.HSSFCellStyle;

import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
//import org.apache.poi.ss.usermodel.Font;


public class ExcelUtil {
	
	/**
	 * POI 엑셀다운로드시 Cell 스타일을 구한다.
	 * 
	 * @param wb
	 * @param fontSize
	 * @param fontWeight
	 * @param align
	 * @param border
	 * @param background
	 * @param number
	 * @return
	 */
	public static HSSFCellStyle getCellStyle(HSSFWorkbook wb, int fontSize, int fontWeight, int align, boolean border, boolean background, boolean number) {
		
		HSSFFont font = wb.createFont();
		font.setFontHeightInPoints((short)fontSize);
		font.setFontName("맑은 고딕");
		font.setBoldweight((short)fontWeight);
		
		HSSFCellStyle style = wb.createCellStyle(); 
		style.setFillBackgroundColor(HSSFColor.BLACK.index); 
		if (background) {
			style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); 
			style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); 
		}

		style.setFont(font);
		style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
		style.setAlignment((short)align);
		
		if (border) {
			style.setBorderBottom(HSSFCellStyle.BORDER_THIN); 
			style.setBottomBorderColor(HSSFColor.GREY_50_PERCENT.index); 
			style.setBorderLeft(HSSFCellStyle.BORDER_THIN); 
			style.setLeftBorderColor(HSSFColor.GREY_50_PERCENT.index); 
			style.setBorderRight(HSSFCellStyle.BORDER_THIN); 
			style.setRightBorderColor(HSSFColor.GREY_50_PERCENT.index); 
			style.setBorderTop(HSSFCellStyle.BORDER_THIN); 
			style.setTopBorderColor(HSSFColor.GREY_50_PERCENT.index); 
		}
		
		if (number) {
			style.setDataFormat((short) 3);
		} 
		
		return style;
	}
}
